package top.lisicheng.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.lisicheng.model.CommonResult;
import top.lisicheng.model.Payment;
import top.lisicheng.service.PaymentService;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @author Lisicheng
 */
@RequestMapping("payment")
@RestController
@Slf4j
public class PaymentController {

    @Resource
    private PaymentService paymentService;

    @RequestMapping("add")
    public CommonResult add(Payment payment) {
        boolean result = paymentService.save(payment);
        if (result) {
            return new CommonResult(200, "成功了");
        }
        return new CommonResult(500, "失败");
    }

    @RequestMapping("get")
    public CommonResult get(Long id) {
        log.info("查询：id：" + id);
        return new CommonResult<>(200, "成功8001", paymentService.getById(id));
    }

    @RequestMapping("timeout")
    public CommonResult timeout() {
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return new CommonResult(200, "休眠3s");
    }
}
